package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GD;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 效果1："夺魄"技能系数提升27%，并随机溅射1个目标造成40%的技能伤害
 * 效果2：受到非致死伤害时，每损失10%生命值获得1层【幽魂】，并提升自身5%攻击力，最高10层，死亡后清除，不可驱散！
 * 效果3：每次死亡对敌方全体造成90%攻击力伤害，每层【幽魂】增加15%系数，无冷却
 */
public class 黑女巫糖果灵器PH extends PassiveHandler {

	private String 溅射技能标签;
	private double 溅射血量调整;

	private int 血量损失;
	private int 幽魂buff;

	private double 死亡伤害系数;
	private double buff系数;

	//溅射技能标签=女巫恶作剧&溅射血量调整=-6000&
	//血量损失=1000&幽魂buff=？？&
	//死亡伤害系数=9000&buff系数=1500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		溅射技能标签 = args.get("溅射技能标签");
		溅射血量调整 = args.getWDouble("溅射血量调整", 0d);

		血量损失 = args.getInt("血量损失", 0);
		幽魂buff = args.getInt("幽魂buff", 0);

		死亡伤害系数 = args.getWDouble("死亡伤害系数", 0d);
		buff系数 = args.getWDouble("buff系数", 0d);
	}

	@Override
	public void beforeOwnerMove(MoveCtx move, TimeActionCtx action) {
		if (move.getSkill().cfg.containTag(溅射技能标签)) {
			move.getSkill().param.addTargetNum(1);
		}
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (action.getSkill().cfg.containTag(溅射技能标签)) {
			for (Fighter exTarget : action.getExTargets()) {
				effect.getTargetCtx(exTarget.getPid()).addHpChangeRate(溅射血量调整);
			}
		}
	}

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		if (血量损失 <= 0 || 幽魂buff <= 0) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		int buffNum = (int) (totalDamage / skill.owner.attr.total().hpTotal() * GD.W_10000_0 / 血量损失);
		if (buffNum > 0) {
			skill.owner.buff.tryAddSome(action, skill.owner, 幽魂buff, buffNum);
		}
	}

	@Override
	public void beforeOtherDead(ActionCtx action, Fighter fighter) {
		if (fighter.getPid() != skill.owner.getPid()) {
			return;
		}
		if (死亡伤害系数 <= 0 && buff系数 <= 0) {
			return;
		}
		double coeff = 死亡伤害系数 + skill.owner.buff.countBuffByTid(幽魂buff) * buff系数;
		double damage = skill.owner.attr.attTotal() * coeff;
		for (Fighter target : action.getTeamVs().getEnemyTeam(skill.owner.getTeam()).getFightersAlive()) {
			target.attr.passiveHurt(action, skill.owner, damage);
		}
	}
}
